package com.zhiche.lisa.bms.service.sta.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zhiche.lisa.bms.dao.mapper.sta.AmgCstMapper;
import com.zhiche.lisa.bms.dao.model.sta.AmgCst;
import com.zhiche.lisa.bms.service.sta.AmgCstService;
import com.zhiche.lisa.bms.utils.ToolCommonUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 车系对照表 服务实现类
 * </p>
 *
 * @author linbao
 * @since 2018-11-25
 */
@Service
public class AmgCstServiceImpl extends ServiceImpl<AmgCstMapper, AmgCst> implements AmgCstService {

    /**
     * 根据车型匹配对应的车系
     *
     * @param carService
     * @param transTypeName
     * @param ciamsName
     * @param dispatchDate  发运时间
     * @return
     */
    @Override
    public String getCarServiceByVehicelName(String carService, String transTypeName, String ciamsName, Date dispatchDate) {
        if (StringUtils.isNotBlank(carService) && StringUtils.isNotBlank(transTypeName)) {
            EntityWrapper<AmgCst> ew = new EntityWrapper<>();
            ew.eq("vehicle_model_name", carService);
            ew.eq("transport_mode_xid", transTypeName);
            ew.eq("ciams_name", ciamsName);
            if (dispatchDate != null) {
                ew.le("start_date", dispatchDate);
                ew.ge("expire_date", ToolCommonUtils.getStartOfDate(dispatchDate));
            }
            List<AmgCst> amgCsts = this.selectList(ew);
            if (!CollectionUtils.isEmpty(amgCsts)) {
                return amgCsts.get(0).getMg1();
            }
        }
        return null;
    }
}
